package logic

import (
	"context"
	"shop_ppl/order_srv/model/mysql"

	"shop_ppl/order_srv/internal/svc"
	"shop_ppl/order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
	return &CreateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateOrderLogic) CreateOrder(in *order.CreateOrderRequest) (*order.CreateOrderResponse, error) {
	og := mysql.Goods{
		GoodsTitle: in.OrderTitle,
		GoodsPrice: in.OrderPrice,
		GoodsNum:   in.OrderNum,
	}
	err := og.CreateIn()
	if err != nil {
		logx.Error("创建失败", err)
		return nil, err
	}
	return &order.CreateOrderResponse{}, nil
}
